package bill.study.playground;
public class Sandbox {	
	private final static int a = Attribute.A.ordinal();
	private final static int b = Attribute.B.ordinal();;
	private final static int c = Attribute.C.ordinal();;
	public enum Attribute { A, B, C }
	
	public Sandbox() {
		try {
			log("Start");
			printDivider();

			viewObjectCode(a);		// feed the view object code some attribute ordinals
			viewObjectCode(b);
			viewObjectCode(c);
			viewObjectCode(3);
			
			printDivider();
			log("End");
		} catch (Exception e) {
			log(e);
			e.printStackTrace();
		}		
	}
	
	// This method probably takes about as long as a big if/else
	public final static Attribute getAttribute(int ordinal) {
		for(Attribute enumeration : Attribute.values()) {
			if(enumeration.ordinal() == ordinal) {
				return enumeration;
			}
		}
		
		return null;
	}
	
	public void viewObjectCode(int x) {			
		// Call getAttribute to get an enum item that maps to the given ordinal
		Attribute e = getAttribute(x);
		if(e != null) {
			// Run through the more-readable switch/case
			switch(e) {
				case A:
					log("Enumeration: [A]");
					break;
				case B:
					log("Enumeration: [B]");
					break;	
				case C:
					log("Enumeration: [C]");
					break;
				default:
					log("Could not find enumeration item that corresponds with the integer value: [" + x + "]");
					break;
			}
		} else {
			log("Could not find enumeration item that corresponds with the integer value: [" + x + "]");
		}
	}
	
	public void printDivider() {
		log("-----------------------------------------------------------------------------------------");
	}
	
	public void log(Object message) {
		System.out.println(message);
	}
	
	public static void main(String[] args) {
		new Sandbox();
	}
}